﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Sol136
{

    public int Single1(int[] nums)//hash,也就是字典
    {
        int len=nums.Length;
        
        Dictionary<int,int> map = new Dictionary<int,int>();

        for (int i = 0; i < nums.Length; i++)
        {
            if (!map.TryGetValue(nums[i],out int val))//没有遇到
            {
                map[nums[i]] = 1;
            }
            else//再次遇到
            {
                map[nums[i]] = 0;
            }
           
 
        }
      foreach (var pair in map)
        {
            if(pair.Value==1)
            {
                return pair.Key;
            }

        }

        return -1;
       

    }
    public int Single3(int[] nums)//异或
    { 
        int sum= 0; 


        for(int i=0; i < nums.Length; i++)
        {
            sum = sum ^ nums[i];
        }
        return sum;
    }   
    public int Single(int[] nums)//使用集合存，也就是ArrayList，List<T>,保证没有重复
    { 
       List<int> list = new List<int>();


        for(int i=0; i < nums.Length; i++)
        {
            if (list.Contains(nums[i]))
            {
                list.Remove(nums[i]);
            }
            else
            {
                list.Add(nums[i]);
            }
            

        }
        return list[0];
    }
    }
class Program136
{

    static void Main136(string[] args)
    {


        int[] nums = { 1, 2, 2 };
        Sol136 sol136 = new Sol136();  
        int res=sol136.Single(nums);
        Console.WriteLine(res);
        Console.ReadKey();

    }
}
